<template>
	<view class="bgDefault default-page">
		<tn-nav-bar fixed>基础设置</tn-nav-bar>
		
		<view :style="{paddingTop: vuex_custom_bar_height + 'px'}">
			<view class="container">
			  <tn-list-view
			    :card="true"
			    backgroundColor="#EFEFEF"
			  >
					<block v-for="(item, index) in settingNav" :key="index">
			          <tn-list-cell @tap="clickNav(item)" :arrow="true" :arrowRight="true">{{item.name}}</tn-list-cell>
			        </block>
					
			  </tn-list-view>
			  
			  
			  <view class="submit-btn" width="100%" @click="submit">退出登陆</view>
			</view>
			
			
		</view>
		
		<wx-user-info-modal
		  v-model="showAuthorizationModal"
		  @updated="updatedUserInfoEvent"
		></wx-user-info-modal>
	</view>
</template>

<script>
	import WxUserInfoModal from '@/uni_modules/tuniaoui-wx-user-info/components/tuniaoui-wx-user-info/tuniaoui-wx-user-info.vue'
	import {uploadUrl} from '@/api/user/login.js'
	import {updateInfo} from '@/api/user/index.js'
	import store from '../../store'
	export default {
		components:{WxUserInfoModal},
		data() {
			return {
				showAuthorizationModal: false,
				settingNav:[
					{
						name:"个人资料",
						url:"",
						index:0
					},
					{
						name:"帮助中心",
						url:"/pages/user/article/help",
						index:1
					},
					{
						name:"清除缓存",
						url:"",
						index:2
					}
				]
			}
		},
		methods: {
			clickNav(item){
				if(item.index == 0){
					this.showAuthorizationModal = true
				}else{
					uni.navigateTo({
					  url: item.url
					})
				}
				
			},
			submit(){
				uni.navigateTo({
				  url: "/pages/public/login?resetToken=1"
				})
			},
			// 获取到的用户信息
			updatedUserInfoEvent(info) {
				
				uni.uploadFile({
					url:uploadUrl,
					filePath:info.avatar,
					name:"image",
					success:(res)=> {
						var data = JSON.parse(res.data)
						
						if(res.statusCode != 200 || data.code !=200){
							uni.showToast({
								icon: 'none',
								title: '图片上传失败 ' + res.errMsg
							})
							return false
						}
						info.avatar = data.data.url
						
						
						updateInfo(info).then(res=>{
							uni.showToast({
								icon: 'none',
								title: '修改成功 '
							})
							
							this.showAuthorizationModal = false
						})
						console.log('获取到的用户信息', info)
					}
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
  .bgDefault{
  	background: $tn-main-bg;
  }
  
  .default-page {
    width: 100vw;
    height: 100vh;
    /* display: flex; */
    align-items: center;
    justify-content: center;
  	font-family: "微软雅黑";
  }
  .container{
	  padding: 5px 10px 15px;
	  width: calc(100% - 30px);
	  background-color: #FFFFFF;
	  box-shadow: 0px 5px 25px 0px rgba(0, 3, 72, 0.1);
	  margin: 18px 15px 2px 15px;
	  border-radius: 10px;
	  position: relative;
	  align-items: center;
	  
	  /* 授权按钮 */
	  .submit-btn {
	    background: $tn-main-orange;
	  		width: 90%;
	    color: #FFFFFF;
	    border-radius: 20rpx;
	    font-size: 28rpx;
	    margin: 40rpx auto;
	  		line-height: 36px;
	  		text-align: center;
	  }
  }
  
  
</style>
